﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DotNet.Random.IdCard;

namespace DotNet.Random
{
    /// <summary>
    /// 存放静态方法，
    /// </summary>
    public class RandService
    {
        #region current

        /// <summary>
        /// Rands the date time current year.
        /// 随机当前年的时间
        /// </summary>
        /// <returns></returns>
        public static System.DateTime RandDateTimeCurrentYear()
        {
            var year = new DotNet.Random.Date.CurrenYearRandService();
            var month = new DotNet.Random.Date.MonthRandService();
            var day = new DotNet.Random.Date.DayRandService();
            var hour = new DotNet.Random.Time.HourRandService();
            var minute = new DotNet.Random.Time.MinuteRandService();
            var second = new DotNet.Random.Time.SecondRandService();
            var mill = new DotNet.Random.Time.MillisecondRandService();
            var dateTimeRand = new DotNet.Random.DateTime
                .DateTimeRandService(year, month, day, hour, minute, second, mill);
            var res = dateTimeRand.Rand();
            return res;
        }

        /// <summary>
        /// Rands the date time current year month.
        /// 随机当前年月的时间
        /// </summary>
        /// <returns></returns>
        public static System.DateTime RandDateTimeCurrentYearMonth()
        {
            var year = new DotNet.Random.Date.CurrenYearRandService();
            var month = new DotNet.Random.Date.CurrentMonthRandService();
            var day = new DotNet.Random.Date.DayRandService();
            var hour = new DotNet.Random.Time.HourRandService();
            var minute = new DotNet.Random.Time.MinuteRandService();
            var second = new DotNet.Random.Time.SecondRandService();
            var mill = new DotNet.Random.Time.MillisecondRandService();
            var dateTimeRand = new DotNet.Random.DateTime
                .DateTimeRandService(year, month, day, hour, minute, second, mill);
            var res = dateTimeRand.Rand();
            return res;
        }

        /// <summary>
        /// Rands the date time current year month day.
        /// 随机当前年月日的时间
        /// </summary>
        /// <returns></returns>
        public static System.DateTime RandDateTimeCurrentYearMonthDay()
        {
            var year = new DotNet.Random.Date.CurrenYearRandService();
            var month = new DotNet.Random.Date.CurrentMonthRandService();
            var day = new DotNet.Random.Date.CurrentDayRandService();
            var hour = new DotNet.Random.Time.HourRandService();
            var minute = new DotNet.Random.Time.MinuteRandService();
            var second = new DotNet.Random.Time.SecondRandService();
            var mill = new DotNet.Random.Time.MillisecondRandService();
            var dateTimeRand = new DotNet.Random.DateTime
                .DateTimeRandService(year, month, day, hour, minute, second, mill);
            var res = dateTimeRand.Rand();
            return res;
        }

        /// <summary>
        /// Rands the date time current year month day hour.
        /// 随机当前年月日小时的时间
        /// </summary>
        /// <returns></returns>
        public static System.DateTime RandDateTimeCurrentYearMonthDayHour()
        {
            var year = new DotNet.Random.Date.CurrenYearRandService();
            var month = new DotNet.Random.Date.CurrentMonthRandService();
            var day = new DotNet.Random.Date.CurrentDayRandService();
            var hour = new DotNet.Random.Time.CurrentHourRandService();
            var minute = new DotNet.Random.Time.MinuteRandService();
            var second = new DotNet.Random.Time.SecondRandService();
            var mill = new DotNet.Random.Time.MillisecondRandService();
            var dateTimeRand = new DotNet.Random.DateTime
                .DateTimeRandService(year, month, day, hour, minute, second, mill);
            var res = dateTimeRand.Rand();
            return res;
        }

        /// <summary>
        /// Rands the date time current year month day hour minute.
        /// 随机当前年月日小时分钟的时间
        /// </summary>
        /// <returns></returns>
        public static System.DateTime RandDateTimeCurrentYearMonthDayHourMinute()
        {
            var year = new DotNet.Random.Date.CurrenYearRandService();
            var month = new DotNet.Random.Date.CurrentMonthRandService();
            var day = new DotNet.Random.Date.CurrentDayRandService();
            var hour = new DotNet.Random.Time.CurrentHourRandService();
            var minute = new DotNet.Random.Time.CurrentMinuteRandService();
            var second = new DotNet.Random.Time.SecondRandService();
            var mill = new DotNet.Random.Time.MillisecondRandService();
            var dateTimeRand = new DotNet.Random.DateTime
                .DateTimeRandService(year, month, day, hour, minute, second, mill);
            var res = dateTimeRand.Rand();
            return res;
        }

        #endregion

        #region yeaterday

        /// <summary>
        /// Rands the date time current year month yesterday.
        /// 随机当前年月昨天的时间
        /// </summary>
        /// <returns></returns>
        public static System.DateTime RandDateTimeCurrentYearMonthYesterday()
        {
            var year = new DotNet.Random.Date.CurrenYearRandService();
            var month = new DotNet.Random.Date.CurrentMonthRandService();
            var day = new DotNet.Random.Date.YesterdayRandService();
            var hour = new DotNet.Random.Time.HourRandService();
            var minute = new DotNet.Random.Time.MinuteRandService();
            var second = new DotNet.Random.Time.SecondRandService();
            var mill = new DotNet.Random.Time.MillisecondRandService();
            var dateTimeRand = new DotNet.Random.DateTime
                .DateTimeRandService(year, month, day, hour, minute, second, mill);
            var res = dateTimeRand.Rand();
            return res;
        }

        #endregion

        #region rand date time

        /// <summary>
        /// Rands the date time.
        /// 随机一个时间
        /// </summary>
        /// <returns></returns>
        public static System.DateTime RandDateTime()
        {
            var year = new DotNet.Random.Date.YearRandService();
            var month = new DotNet.Random.Date.MonthRandService();
            var day = new DotNet.Random.Date.DayRandService();
            var hour = new DotNet.Random.Time.HourRandService();
            var minute = new DotNet.Random.Time.MinuteRandService();
            var second = new DotNet.Random.Time.SecondRandService();
            var mill = new DotNet.Random.Time.MillisecondRandService();
            var dateTimeRand = new DotNet.Random.DateTime
                .DateTimeRandService(year, month, day, hour, minute, second, mill);
            var res = dateTimeRand.Rand();
            return res;
        }

        /// <summary>
        /// Rands the date time.
        /// 随机一个时间
        /// </summary>
        /// <param name="min">The min.开始时间</param>
        /// <param name="max">The max.结束时间</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentException"></exception>
        public static System.DateTime RandDateTime(System.DateTime min, System.DateTime max)
        {
            var rand = new System.Random();
            if (max <= min)
            {
                string message = "Max must be greater than min.";
                throw new ArgumentException(message);
            }
            long minTicks = min.Ticks;
            long maxTicks = max.Ticks;
            double rn = (Convert.ToDouble(maxTicks) - Convert.ToDouble(minTicks)) * rand.NextDouble()
               + Convert.ToDouble(minTicks);
            return new System.DateTime(Convert.ToInt64(rn));
        }

        #endregion

    }
}
